﻿/* You are given a text. 
 * Write a program that changes the text in all regions surrounded by the tags 
 * <upcase> and </upcase> to uppercase. 
 * The tags cannot be nested. 
 * Example:
We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything
</upcase>else.
 * The expected result:
We are living in a YELLOW SUBMARINE. We don't have ANYTHING else */
using System;
using System.Text.RegularExpressions;

namespace _5.Upcase
{
    class Upcase
    {
        static void Main()
        {
            Console.Write("Text to replace the <upcase><string></upcase> tags with uppercase: ");
            string text = Console.ReadLine();

            //text = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase>else.";
            string regexpattern = @"<upcase>(.*?)</upcase>";
            Regex r = new Regex(@regexpattern, RegexOptions.Compiled);

            //Console.WriteLine();
            text = r.Replace(text, RegExUpcase);
            Console.WriteLine(text);

        }

        private static string RegExUpcase(Match match)
        {
            return string.Format(@"{0}", match.Groups[1].Value.ToUpper());
        }
    }
}
